from flask import g

from .db import create_scoped_session


"""数据库函数
"""
def db_scoped_session_init():
    """初始化数据库连接
    """
    g.Session = create_scoped_session()


def db_scoped_session_remove():
    """删除数据库连接
    """
    if g.get('Session'):
        g.get('Session').remove()


def dbh():
    """获取数据库连接
    """
    return g.get('Session')()
